package com.example.demo.result;

import com.example.demo.exception.CodeMsg;

public class Result<T> {
    private int code;
    private String msg;
    private T data;//由外部指定类型

    public Result(T data){
        this.data=data;
    }

    public Result(int code,String msg){
        this.code=code;
        this.msg=msg;
    }

    public Result(CodeMsg codeMsg){
        if (codeMsg!=null){
            this.code=codeMsg.getCode();
            this.msg=codeMsg.getMsg();
        }
    }
    public static <T> Result success(T data){
        Result result = new Result(data);
        return result;
    }

    public static Result error(CodeMsg codeMsg){
        return new Result(codeMsg);
    }


    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
